<!DOCTYPE html>
<html lang="en">
<head th:include="certificateWeb/headFoot :: headerCss">
</head>
<!--<link href="/css/web/themes/about.css" rel="stylesheet">-->
<link rel="stylesheet" href="/css/certificateWeb/workNews/workNews.css">
<body id="body">
<div th:include="certificateWeb/headFoot :: header"></div>
<main id="main" >
    <section class="sec_1">
        <div class="div_1">
            <ul>
                <li><a href="/certificate/my">个人信息</a></li>
                <li><a href="/certificate/isResume">我的简历</a></li>
                <!-- <li><a href="/certificate/findApplyExam">报名记录</a></li> -->
                <li><a href="/certificate/infoRecordList">表单提交记录</a></li>
                <li><a href="/certificate/expertRecordList">专家申请记录</a></li>
                <li><a href="/certificate/stationRecordList">考核站点申请记录</a></li>
                <li><a href="/certificate/stationPxRecordList">培训基地申请记录</a></li>
                <li><a href="/certificate/gradeQuery">成绩查询</a></li>
                <li class="this"><a href="/certificate/message">消息中心</a></li>
                <li onclick="mock2(this)" data-type="2"><a>幼儿照护初级模拟考试</a></li>
                <li onclick="mock2(this)" data-type="1"><a>幼儿照护中级模拟考试</a></li>
                <li onclick="mock2(this)" data-type="0"><a>幼儿照护高级模拟考试</a></li>
            </ul>
        </div>
        <div class="div_2">
            <div id="msg"></div>
            <div id="page" class="page"></div>
        </div>

        <div style="clear: both"></div>
    </section>
</main>
<div th:include="certificateWeb/headFoot :: footer"></div>
<script type="text/javascript" src="/js/mobile.js"></script>
<script>
    $(function () {
        ajaxToken("/jzApi/user/msgListApi", "GET", {
            type: 0,
            state: '',
            current: 1,
            number: 14
        }, function (res) {

            if (res.pages == 0) {
                $("#msg").html('<div class="noData">暂无数据</div>');
            } else {
                var list = res.records;
                var news = '';
                list.forEach(function (item, index) {
                    var a = '', b = '';
                    if (item.state == 0) {
                        a = '<span class="read">未读</span>'
                    } else if (item.state == 2) {
                        a = '<span class="readed">已读</span>'
                    }
                    if (item.enclosure != '' && item.enclosure != null) {
                        b = '<div><a href="' + item.enclosure + '" download style="text-decoration: underline;color: #649745" >附件下载</a></div>'
                    }
                    news += '<div href="#" class="message" data-id="' + item.id + '" data-state="' + item.state + '" onclick="msg(this)">' +
                        '<div class="flex1"><input type="hidden" value="' + item.id + '" id="msgId" />' +
                        '<span class="span_2">' + item.title + a + '</span>' +
                        '<span class="span_1">' + item.createrDate + '</span></div>' +
                        '<div class="s change content1">' + item.content + b + '</div></div>';
                });
                $("#msg").html(news);
                page(1, res.pages);
            }
        });
        $(".div_2").on("click", ".span_2", function () {
            $(this).parents(".message").find(".s").toggleClass("change");
            $(this).parents(".message").toggleClass("bg_shadow");
            $(this).parents(".message").siblings().find(".s").addClass("change");
            $(this).parents(".message").siblings().removeClass("bg_shadow");
        })
    });

    function msg(that) {
        var id = $(that).attr("data-id");
        var state = $(that).attr("data-state");
        if (state == 0) {
            ajaxToken("/jzApi/user/updateStateApi", "GET", {
                id: id
            }, function (res) {
                ajaxToken("/jzApi/user/unreadNumApi", "GET", {
                    type: 0
                }, function (res) {
                    window.localStorage.setItem("unreadNum0", res);
                });
                $(that).find(".read").html("已读");
                $(that).find(".read").addClass("readed");
            });
        }
    }

    function page(num, tolPages) {
        $("#page").paging({
            nowPage: Number(num), // 当前页码
            pageNum: Number(tolPages), // 总页码
            buttonNum: 10, //要展示的页码数量
            canJump: 1,// 是否能跳转。0=不显示（默认），1=显示
            showOne: 0,//只有一页时，是否显示。0=不显示,1=显示（默认）
            callback: function (num) { //回调函数
                ajaxToken("/jzApi/user/msgListApi", "GET", {
                    type: 0,
                    state: '',
                    current: num,
                    number: 14,
                    t: new Date()
                }, function (res) {
                    var list = res.records;
                    var news = '';
                    list.forEach(function (item, index) {
                        var a = '', b = '';
                        if (item.state == 0) {
                            a = '<span class="read">未读</span>'
                        } else if (item.state == 2) {
                            a = '<span class="readed">已读</span>'
                        }
                        if (item.enclosure != '' && item.enclosure != null) {
                            b = '<div><a href="' + item.enclosure + '" download style="text-decoration: underline;color: #649745" >附件下载</a></div>'
                        }
                        news += '<div href="#" class="message" data-id="' + item.id + '" data-state="' + item.state + '" onclick="msg(this)">' +
                            '<div class="flex1"><input type="hidden" value="' + item.id + '" id="msgId" />' +
                            '<span class="span_2">' + item.title + a + '</span>' +
                            '<span class="span_1">' + item.createrDate + '</span></div>' +
                            '<div class="s change content1">' + item.content + b + '</div></div>';
                    });
                    $("#msg").html(news);

                });
            }
        });
    }
</script>
<script type="text/javascript" src="/js/xlPaging.js"></script>
</body>
</html>